import { createRouter, createWebHistory } from 'vue-router'
import Layout from "../views/Layout.vue"
import { Notify } from 'vant'

const routes = [
  {
    path: '/',
    redirect: '/logo',
  },
  {
    path: '/layout',
    name: 'layout',
    component: <Layout />,
    children: [{
      path: '/logo',
      name: 'logo',
      component: () => import("../views/layout/Logo.vue"),
      meta: {
        auth: 2
      }
    }, {
      path: '/train',
      name: 'train',
      component: () => import("../views/Train/Train.vue"),
      meta: {
        auth: 1
      }
    }, {
      path: '/addtrain',
      name: 'addtrain',
      component: () => import("../views/Train/Addtrain.vue"),
      meta: {
        auth: 1
      }
    }, {
      path: '/seat/:id',
      name: 'seat',
      component: () => import("../views/Train/Seat.vue"),
      meta: {
        auth: 1
      }
    }, {
      path: '/user',
      name: 'user',
      component: () => import("../views/Set/User.vue"),
      meta: {
        auth: 1
      }
    }, {
      path: '/city',
      name: 'city',
      component: () => import("../views/Set/City.vue"),
      meta: {
        auth: 2
      }
    }, {
      path: '/station',
      name: 'station',
      component: () => import("../views/Station/Station.vue"),
      meta: {
        auth: 2
      }
    }, {
      path: '/line',
      name: 'line',
      component: () => import("../views/Line/Line.vue"),
      meta: {
        auth: 2
      }
    }, {
      path: '/ticket',
      name: 'ticket',
      component: () => import("../views/Ticket/Ticket.vue"),
      meta: {
        auth: 2
      }
    }, {
      path: '/ticketdetail/:id',
      name: 'ticketdetail',
      component: () => import("../views/Ticket/TicketDetail.vue"),
      meta: {
        auth: 1
      }
    }, {
      path: '/order',
      name: 'order',
      component: () => import("../views/Orders/Order.vue"),
      meta: {
        auth: 2
      }
    }, {
      path: '/personal',
      name: 'personal',
      component: () => import("../views/layout/Personal.vue"),
      meta: {
        auth: 2
      }
    }, {
      path: '/role',
      name: 'role',
      component: () => import("../views/Set/Role.vue"),
      meta: {
        auth: 2
      }
    }]
  }, {
    path: '/login',
    name: 'login',
    component: () => import("../views/login/Login.vue")
  }, {
    path: '/sign',
    name: 'sign',
    component: () => import("../views/login/Sign.vue")
  }, {
    path: '/change',
    name: 'change',
    component: () => import("../views/login/ChangePass.vue")
  }, {
    path: `/:path(.*)`,
    name: '404',
    component: () => import("../views/Error.vue")
  },
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

//  首位 
// let white = ['/login', '/sign', '/change']
// router.beforeEach((to, from) => {
//   let token = JSON.parse(localStorage.getItem('token'))
//   if (!white.includes(to.path) && !token) {
//     Notify({
//       message: '需要登录',
//       type: "warning"
//     })
//     return '/login'
//   }
// })

export default router
